<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>客户建议</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>
<div style="width:100%;">

    <!--{include file='comm/menu.tpl'}-->

    <div class="title">
        <h2 class="tac">建议有礼</h2>
    </div>

    <div  class="search-box">
        <form id="searchForm" name="searchForm" onsubmit="return false;">
            <div style="position:relative">

                <span>
                    联系人：
                    <input type="text" id="custName" name="custName" style="width: 120px;" />
                </span>

                <span>
                    创建时间：
                    <input type="text" id="startDate" name="startDate" readonly="readonly" style="width: 120px;" />
                    ～
                    <input type="text" id="endDate" name="endDate" readonly="readonly" style="width: 120px;" />
                </span>
                <span>
                    状态：
                    <select name="suggestStatus" id="suggestStatus">
                        <option value="3">请选择</option>
                        <option value="0">建立</option>
                        <option value="1">审核</option>
                        <option value="2">作废</option>
                    </select>
                </span>
                <span>
                    <input type="button" class="btn" value="查询" onclick="suggest.search();">&nbsp;&nbsp;
                    <input type="button" class="btn" value="重置" onclick="suggest.clear();">
                </span>

            </div>
        </form>
    </div>

    <table id="flex" style="display:none"></table>

    <!--{include file='comm/footer.tpl'}-->

</div>
<script type="text/javascript">

    cal.manageFields("startDate", "startDate", "%Y-%m-%d");
    cal.manageFields("endDate", "endDate", "%Y-%m-%d");

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/content/custSuggest.ajax?operFlg=1&xjx=none",
        dataType: "json",
        colModel : [
            <!--{if $edit_permission}-->
            {display: "操作", width : 120, align: 'center'},
            <!--{/if}-->
            {display: "联系人", width : 100, align: 'left',  name : "couponID", sortable : true},
            {display: "联系手机", width : 120, align: 'center' },
            {display: "创建时间", width : 138, align: 'center'},
            {display: "内容", width : 180, align: 'left'},
            {display: "状态", width : 80, align : 'center'},
            {display: "处理备注", width : 180, align : 'left'},
            {display: "处理人", width : 100, align : 'left'},
            {display: "处理时间", width : 138, align : 'center'}
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "删除", bclass: "delete", onpress : "suggest.suggestDelete"}
        ],
        <!--{/if}-->
        sortname: "createTime",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true
    });

    var suggest = {

        search: function(){

            $msg = '';

            if($('#startDate').val()>$('#endDate').val())
                $msg = '开始时间不能大于结束时间';

            if($msg)
                E.alert($msg);

            var dt = $('#searchForm').serializeArray();
            $("#flex").flexOptions({newp: 1,params: dt}).flexReload();
        },
        suggestDelete: function(){

            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    suggest.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择删除客户建议");
            else
                E.confirm("您确认要删除选中的客户建议吗？","suggest.deleteConfirm");

        },
        deleteConfirm: function(){
            $.ajax({
                type:"post",
                url:"/invokingAjax-backend/content/custSuggest.ajax?operFlg=2&xjx=none",
                data:{"delete_str":this.delete_str},
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "suggest.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
        load: function(){
            $('#flex').flexReload();
        },
        handle: function(suggestID){

            $.ajax({
                type:"post",
                url:"/invokingAjax-backend/content/custSuggest.ajax?operFlg=3&xjx=none",
                data:{"suggestID":suggestID},
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {

                        var html = "<form name='suggestHandle' id='suggestHandle'>" +
                                "<input type='hidden' name='pcustID' value='"+result_obj.suggest_data[0].pcustID+"'>" +
                                "<input type='hidden' name='custID' value='"+result_obj.suggest_data[0].custID+"'>" +
                                "<input type='hidden' name='suggestID' value='"+result_obj.suggest_data[0].suggestID+"'>" +
                                "<table>" +
                                "<tr>" +
                                        "<td class='tar'>" +
                                        "建议时间：" +
                                        "</td>" +
                                        "<td>" +
                                        result_obj.suggest_data[0].createTime +
                                        "</td>" +
                                "</tr>" +
                                "<tr>" +
                                        "<td class='tar'>" +
                                                "建议内容：" +
                                        "</td>" +
                                        "<td><div style='word-wrap:break-word;width:360px'>" +
                                                result_obj.suggest_data[0].content +
                                         "</td></div>" +
                                "</tr>" +
                                "<tr>" +
                                           "<td class='tar'>" +
                                                 "处理状态：" +
                                           "</td>" +
                                           "<td>" +
                                                 "<input type='radio' checked='checked' name='suggestStatus' value='1'>审核&nbsp;" +
                                                 "<input type='radio' name='suggestStatus' value='2'>作废" +
                                           "</td>" +
                                "<tr>" +
                                "<tr>" +
                                            "<td class='tar'>" +
                                                 "处理备注：" +
                                            "</td>" +
                                            "<td>" +
                                                 "<textarea style='width:360px;height:80px' name='reply' id='reply' type='textarea'></textarea>" +
                                            "</td>" +
                                "</tr>" +
                                "</table>" +
                                "</form>";
                        E.popup.open({
                            content: html,
                            title: '客户建议处理',
                            css: 'width: 488px;',
                            btnName: "处理", //“确认”按钮，不传则不显示
                            btnCall: "suggest.submit();" //点击“确认”按钮触发的函数/方法
                        });

                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });


        },

        clear: function(){
            $('#custName').val('');
            $('#startDate').val('');
            $('#endDate').val('');
            $('#suggestStatus').val('');
        },

        submit: function(){
            E.loadding.open('正在处理客户建议，请稍候...');
            var dt = E.getFormValues('suggestHandle');
            $.ajax({
                type:"post",
                url:"/invokingAjax-backend/content/custSuggest.ajax?operFlg=4&xjx=none",
                data:{'dt':dt},
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.loadding.close();
                        E.alert(result_obj.message, 2, "suggest.load");
                        E.popup.close();
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        }

    }


</script>
</body>
</html>